package com.ki.erp.service.impl;

import com.ki.erp.entity.User;
import com.ki.erp.pl.UserPlImpl;
import com.ki.erp.vo.LoginUserVo;
import jakarta.annotation.Resource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    private @Resource UserPlImpl userPlImpl;


    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userPlImpl.getByName(username);
        if (Objects.isNull(user)) {
            throw new RuntimeException("用户名或密码错误");
        }


        return new LoginUserVo(user);
    }
}
